import { baseURL } from '@/stores/constant'

const request = async <T>(opt : UniApp.RequestOptions) => {
	const opted = { ...opt }
	opted.header = {
		// todo: 我的后端不加这个头，访问不到，后端得想办法改改
		'content-type': 'application/x-www-form-urlencoded'
	}

	if (!opted.url.startsWith('http')) opted.url = `${baseURL}/${opt.url}`
	const res = await uni.request(opted)
	console.debug(opted, res)
	return res.data as T
}

export default request